package structure;

import graphics.MaxGraphics;

import java.awt.Polygon;
import java.awt.Shape;

import main.Game;

import util.Point;

/**
 * The fundamental display object--all it has is it's position, and the methods for
 * retrieving that.
 * 
 * Any SObject should be able to asked about it's mass, drawn to screen, collided with,
 * and have a radius for collision detection.  These methods must be overwritten by the
 * children.  However, getMass() can always return 0, and the others can be made empty.
 * 
 * Can also be flagged for removal by the Game.
 * @author max
 *
 */

public abstract class SObject {
	protected Point cords;
	protected Point vel = new Point(0, 0);
	protected boolean flagged;
	protected int id;
	
	private static final int MAX_X_VEL = 100;
	private static final int MAX_Y_VEL = 100;

	
	public SObject(Point p) {
		id = Game.game.id++;
		this.cords = new Point(p);
	}
	
	public void update() {
		translate(vel);
	}
	
	public void acc(Point p) {
		vel = new Point(Math.min(MAX_X_VEL, vel.getX() + p.getX()), Math.min(vel.getY() + p.getY(), MAX_Y_VEL));
	}
	
	public void setVel(Point p) {
		vel = p;
	}
	
	public double getXVel() {
		return vel.getX();
	}
	
	public double getYVel() {
		return vel.getY();
	}
	
	public Point getVel() {
		return vel;
	}
	
	public double getX() {
		return cords.getX();
	}
	
	public double getY() {
		return cords.getY();
	}
	
	public Point getCords() {
		return cords;
	}
	
	public abstract double getMass();
	
	protected void translate(Point p) {
		this.cords = new Point((this.cords.getX() + p.getX()), (this.cords.getY() + p.getY()));
	}
	
	public boolean isFlagged() {
		return flagged;
	}
	
	public void flag() {
		flagged = true;
	}

	public boolean equals(Object o) {
		if(o instanceof SObject) {
			return ((SObject) o).id == id;
		}
		return false;
	}
	
	public int hashCode() {
		return id;
	}
	
	public int getId() {
		return id;
	}
	
	public void applyForce(Point p) {
		acc(new Point(p.getX() / getMass(), p.getY() / getMass()));
	}
	
	public abstract void draw(MaxGraphics g);
	
	public abstract void collide(SObject s);
	
	public abstract Shape[] getShape();
	public abstract double getRadius();
	
	public abstract String toString();
	


}
